<?php

class mainController extends baseController
{
	public function show(){
		$exp_time = CheckinHelper::passwdExpires( UID );
		if(time()+86400*app_cfg('setting','passwdavalidwarn') > $exp_time){
			$this->assign('exp_time', round(($exp_time-time())/86400,1) );
		}
		$this->display();
	}

	public function chgpass(){
        if(isset($_POST['oldpass'])) {
            $uid = UID;
            if(empty($_POST['newpass'])){
                Show::warn("新密码不能为空");
            }
            if(0!==strcmp($_POST['newpass'], $_POST['reppass'])) {
                Show::warn("两次新密码不一致");
            }

			$user = User::get($uid);
			if($user['passwd']!=UserAuthHelper::encrypt($_POST['oldpass'])){
                Show::warn("旧密码不正确，请重新输入");
			}

			if(CheckinHelper::passwdExists($uid, $_POST['newpass'])){
				Show::warn('近期已使用过此密码，为安全请更换其它密码');
			}
			if(!UserAuthHelper::isValidPasswd($_POST['newpass'])){
				Show::warn('请使用六位以上字母、数字组合的密码');
			}

			if(User::update($uid, array('passwd'=>md5($_POST['newpass'])))){
				CheckinHelper::trackPasswd($uid, $_POST['newpass']);
				Show::note('修改成功');
			}
			else{
				Show::warn('修改失败');
			}
        }

        $this->display();
	}
	
}

?>
